package com.czp.common.service.impl;

import java.util.List;

import com.czp.audit.model.AuditType;
import com.czp.common.mapper.ICommonMapper;
import com.czp.common.service.ICommonService;
import com.czp.dict.model.Dict;
import com.google.gson.Gson;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-8-12
 */
public class CommonServiceImpl implements ICommonService {
	private ICommonMapper commonMapper;
	private Gson gson = new Gson();

	public String queryDictByCode(String code) throws Exception {
		List<Dict> dicts = commonMapper.queryDictByCode(code);
		int size = dicts.size();
		String dictStr[][] = new String[size][2];
		for(int i = 0; i < size; i++) {
			dictStr[i][0] = dicts.get(i).getDictLabel();
			dictStr[i][1] = dicts.get(i).getDictValue();
		}
		return gson.toJson(dictStr);
	}
	
	public String queryAuditTypeInfo(String type) throws Exception {
		List<AuditType> types = commonMapper.queryAuditTypeInfo(type);
		int size = types.size();
		String typeStr[][] = new String[size][2];
		for(int i = 0; i < size; i++) {
			typeStr[i][0] = types.get(i).getId();
			typeStr[i][1] = types.get(i).getAuditName();
		}
		return gson.toJson(typeStr);
	}

	/**
	 * 获取 commonMapper
	 * @return 返回 commonMapper
	 */
	public ICommonMapper getCommonMapper() {
		return commonMapper;
	}

	/**
	 * 设置 commonMapper
	 * @param 对commonMapper进行赋值
	 */
	public void setCommonMapper(ICommonMapper commonMapper) {
		this.commonMapper = commonMapper;
	}
	

}
